<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
JLoader::register('SiteMapGenerator',JPATH_COMPONENT.DS.'helpers'.DS.'SiteMapGenerator.php');

/**
 *
 * Vista para crear un sitemap de la aplicacion.
 * @author Marco Vargas
 *
 */
class linioViewlinio extends JView 
{
 function display($tpl = null) 
  {
//  	header("Pragma: no-cache");
//  	header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');  	
//  	header('Content-Disposition: attachment; filename="'.$file.'"');  	
  	$doc = JFactory::getDocument();
  	$doc->setMimeEncoding('text/xml');
  	$file='sitemap.xml';
  	$path=JPATH_BASE.DS.$file;
	$model = $this->getModel();
	$country = $model->getParam('country','MX');
	$aStdCategories = $model->getMenu($country);
	$sm = new SiteMapGenerator();
	$sm->setAStdCategories($aStdCategories);
	$this->saveSiteMap($sm->creteSiteMap(),$path);
  }
  

  /**
   * 
   * Guardar el sitemap.xml a disco y mostrarlo a pantalla.
   * @param $xml
   * @param $path
   */
  function saveSiteMap($xml,$path){  	
  	$fp = fopen($path,'w');
	fwrite($fp, $xml);
	fclose($fp);  
	echo $xml;	
  }
}
?>